/*function getTypeName(name) {
    if(name==0){
        return "个人";
    }else if(name==1){
        return "公司";
    }else if(name==2){
        return "管理员"
    }
}*/
function oBlur_1() {
    let a = document.getElementById("hostName").value;
    if (a == "") {
        document.getElementById("remind_1").innerHTML = "主机名字不能为空！".fontcolor("red");
        document.getElementById("change_margin_1").style.marginBottom = 1 + "px";
    } else {
        document.getElementById("remind_1").innerHTML = "";
        document.getElementById("change_margin_1").style.marginBottom = 19 + "px";
    }
}

function oBlur_2() {
    let b = document.getElementById("hostIp").value;
    if (b == "") {
        document.getElementById("remind_2").innerHTML = "主机IP不能为空！".fontcolor("red");
        document.getElementById("change_margin_2").style.marginBottom = 1 + "px";
    } else {
        document.getElementById("remind_2").innerHTML = "";
        document.getElementById("change_margin_2").style.marginBottom = 19 + "px";
    }
}

function oBlur_4() {
    let c = document.getElementById("hostState").value;
    if (c == "") {
        document.getElementById("remind_4").innerHTML = "主机简介不能为空！".fontcolor("red");
        document.getElementById("change_margin_4").style.marginBottom = 1 + "px";
    } else {
        document.getElementById("remind_4").innerHTML = "";
        document.getElementById("change_margin_4").style.marginBottom = 19 + "px";
    }
}

function oFocus_1() {
    document.getElementById("remind_1").innerHTML = "";
    document.getElementById("change_margin_1").style.marginBottom = 19 + "px";
}

function oFocus_2() {
    document.getElementById("remind_2").innerHTML = "";
    document.getElementById("change_margin_2").style.marginBottom = 19 + "px";
}

function oFocus_4() {
    document.getElementById("remind_4").innerHTML = "";
    document.getElementById("change_margin_4").style.marginBottom = 19 + "px";
}

window.onload = function(){
    var index = parent.layer.getFrameIndex(window.name);
    var url = window.location.search;//你的地址

    if (url.indexOf("?") != -1) {
        var str = url.substr(1)
        strs = str.split("&");
        var page = strs[0].split("=")[1];
    }
    console.log(page);
    $.ajax({
        url:constUrl+"MonitorHostServlet",
        type:'post',
        data:{
            operateType:"showDetail",
            hostId:page
        },
        dataType:'json',
        success: function(responseText) {
            $("#hostName").val(responseText.datas[0].hostName);
            $("#hostIp").val(responseText.datas[0].hostIp);
            $("#hostState").val(responseText.datas[0].introduction);
            $.ajax({
                url:constUrl+"MonitorHostGroupServlet",
                type:'post',
                data:{
                    operateType:"showAll"
                },
                dataType:'json',
                success: function(responseText) {
                    var hostGroupHtml ='';
                    for(var i=0;i<responseText.datas.length;i++){
                        hostGroupHtml+='<option value="'+(responseText.datas[i].hostGroupId)+'" >'+responseText.datas[i].hostGroupName+'</option>'
                    }
                    $("#hostGroup").append(hostGroupHtml);
                },
                complete: function() {
                },
                error: function() {
                }
            });
        },
        complete: function() {
        },
        error: function() {
        }
    });

    $('#updateHost').click(function () {
        let hostName = $("#hostName").val();
        let hostIp = $("#hostIp").val();
        let hostType = $("#hostType").val();
        let hostState = $("#hostState").val();
        var hostGroupId = $("#hostGroup").val().join(',');
        if(hostName==""||hostIp==""||hostType==""||hostState==""){
            parent.layer.confirm('关键信息未填，不能修改！',{btn:['确定']});
        }else {
            $.ajax({
                url: constUrl + "MonitorHostServlet",
                type: 'post',
                data: {
                    operateType: "alter",
                    hostName: hostName,
                    hostIp: hostIp,
                    introduction: hostState,
                    hostGroup: hostGroupId,
                    hostId:page
                },
                dataType: 'json',
                success: function (dataText) {
                    console.log(dataText.result);
                    if (dataText.result) {
                        parent.layer.confirm('修改成功！', {
                            btn: ['确定']
                        }, function () {
                            parent.location.reload(index);
                            parent.layer.close(index);

                        })

                    }
                },
                complete: function () {
                },
                error: function () {

                }
            });
        }
    });
    $('#closeIframe').click(function(){
        parent.layer.close(index);
    });
}